import { fetchStandardTree } from '@/api/standard'

const state = {
  standardTree: []
}

const mutations = {
  SET_STANDARD_TREE: (state, list) => {
    state.standardTree = list
  }
}

const actions = {
  async getStandardTree({ commit }, standard) {
    try {
      const data = await fetchStandardTree()
      if (data.Message === 'ok') {
        const list = data.Data ? data.Data : []
        list.splice(0, 0,
          { Id: '1', Title: `All Standard` })
        commit('SET_STANDARD_TREE', list)
      }
    } catch (e) {
      console.log(e)
    }
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
